home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / memory & system tools / tinymeter / source / tinymeter_main / display.c next >
C/C++ Source or Header  |  1996-04-07  |  8KB  |  230 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/classusr.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/cghooks.h>
  11. #include <intuition/icclass.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/sghooks.h>
  14. #include <intuition/screens.h>
  15. #include <datatypes/datatypesclass.h>
  16. #include <datatypes/datatypes.h>
  17. #include <datatypes/pictureclass.h>
  18. #include <libraries/SysInfo.h>
  19. #include <graphics/gfxbase.h>
  20. #include <graphics/text.h>
  21. #include <graphics/gfxmacros.h>
  22. #include <utility/tagitem.h>
  23. #include <utility/hooks.h>
  24. #include <string.h>
  25. #include <clib/macros.h>
  26. #include "gaugeclass.h"
  27. #include "tinymeter.h"
  28.  
  29. extern struct Library *RetinaBase;
  30.  
  31. /* the only two globals */
  32.  
  33. extern ULONG    maximum,
  34.                 idle;
  35.  
  36. drawBackground(struct tm_sys_set *set,struct tm_data *data)
  37. {
  38.     struct RastPort *rp=data->win->RPort;
  39.     UWORD x,y;
  40.  
  41.     x=data->win->Width-1;
  42.     y=data->win->Height-1;
  43.  
  44.     if(data->bg_bm)
  45.     {
  46.         BltBitMapRastPort(data->bg_bm,0,0,rp,0,0,x+1,y+1,0xc0);
  47.     }
  48.     else
  49.     {
  50.         SetAPen(rp,data->bg_color);
  51.         RectFill(rp,0,0,data->win->Width-1,data->win->Height-1);
  52.     }
  53.  
  54.     SetAPen(rp,data->bright_color);
  55.     switch (set->bd_type)
  56.     {
  57.         case    bd_simple:
  58.                 RectFill(rp,0,0,x,0);
  59.                 RectFill(rp,0,0,0,y);
  60.                 RectFill(rp,x,0,x,y);
  61.                 RectFill(rp,0,y,x,y);
  62.                 break;
  63.         case    bd_standard:
  64.                 RectFill(rp,0,0,x,0);
  65.                 RectFill(rp,0,0,0,y);
  66.                 SetAPen(rp,data->dark_color);
  67.                 RectFill(rp,x,1,x,y);
  68.                 RectFill(rp,1,y,x,y);
  69.                 break;
  70.         case    bd_double:
  71.                 SetAPen(rp,data->dark_color);
  72.                 RectFill(rp,0,0,x,0);
  73.                 RectFill(rp,0,0,0,y);
  74.                 RectFill(rp,1,y-1,x-1,y-1);
  75.                 RectFill(rp,x-1,2,x-1,y-1);
  76.                 SetAPen(rp,data->bright_color);
  77.                 RectFill(rp,x,1,x,y);
  78.                 RectFill(rp,1,y,x,y);
  79.                 RectFill(rp,1,1,x-1,1);
  80.                 RectFill(rp,1,1,1,y-1);
  81.                 break;
  82.     }
  83. }
  84.  
  85. allocGadgets(struct tm_sys_set *set, struct tm_data *data, Class *gclass)
  86. {
  87.     struct tm_gau_set *many;
  88.     ULONG  i,max,cur,y_pos,j,tmp;
  89.     
  90.     for(i=0,many=data->list;i<data->num_of_gaug;i++)
  91.     {
  92.         switch (many->type)
  93.         {
  94.             case    typ_all:
  95.                     max=AvailMem(MEMF_TOTAL);
  96.                     cur=AvailMem(0L);
  97.                     break;
  98.             case    typ_chip:
  99.                     max=AvailMem(MEMF_CHIP|MEMF_TOTAL);
  100.                     cur=AvailMem(MEMF_CHIP);
  101.                     break;
  102.             case    typ_fast:
  103.                     max=AvailMem(MEMF_FAST|MEMF_TOTAL);
  104.                     cur=AvailMem(MEMF_FAST);
  105.                     break;
  106.             case    typ_largest_total:
  107.                     max=AvailMem(MEMF_TOTAL);
  108.                     cur=AvailMem(MEMF_LARGEST);
  109.                     break;
  110.             case    typ_largest_chip:
  111.                     max=AvailMem(MEMF_TOTAL|MEMF_CHIP);
  112.                     cur=AvailMem(MEMF_LARGEST|MEMF_CHIP);
  113.                     break;
  114.             case    typ_largest_fast:
  115.                     max=AvailMem(MEMF_TOTAL|MEMF_FAST);
  116.                     cur=AvailMem(MEMF_LARGEST|MEMF_FAST);
  117.                     break;
  118.             case    typ_largest_retina:
  119.                     max=Retina_AvailMem(MEMF_TOTAL);
  120.                     cur=Retina_AvailMem(MEMF_LARGEST);
  121.                     break;
  122.             case    typ_volume:
  123.                     getVolsize(set,data,&many->expansion[0]);
  124.                     max=data->volmax;
  125.                     cur=data->volcur;
  126.                     break;
  127.             case    typ_idle:
  128.                     switch (data->executive)
  129.                     {
  130.                         case    idle_none:
  131.                                 max=1024L;
  132.                                 cur=1024L;
  133.                                 SPrintf(&many->format[0],"n.a.");
  134.                                 break;
  135.                         case    idle_executive:
  136.                                 GetCpuUsage(data->si,&data->cpu);
  137.                                 max=(data->cpu.used_cputime_lastsec_hz)<<8;
  138.                                 cur=(data->cpu.used_cputime_lastsec_hz-data->cpu.used_cputime_lastsec)<<8;
  139.                                 break;
  140.                         case    idle_own:
  141.                                 max=maximum;
  142.                                 cur=idle;
  143.                                 break;
  144.                     }
  145.                     break;
  146.             case    typ_retina:
  147.                     if(RetinaBase)
  148.                     {
  149.                         max=Retina_AvailMem(MEMF_TOTAL);
  150.                         cur=Retina_AvailMem(0L);
  151.                     }
  152.                     else
  153.                     {
  154.                         max=1024L;
  155.                         cur=1024L;
  156.                         SPrintf(&many->format[0],"n.a.");
  157.                     }
  158.                     break;
  159.             case    typ_clock_:
  160.                     many->gauge_type=typ_clock;
  161.                     break;
  162.             case    typ_image:
  163.                     break;
  164.             case    typ_none:
  165.                     data->gdg[i]=0L;
  166.                     goto typ_none_1;
  167.                     break;
  168.         }
  169.  
  170.         tmp=i/set->colums;
  171.         y_pos= set->win_border_y+(tmp*set->win_space_y)+((data->gauge_y_size[tmp]-((data->Font[i]->tf_YSize*(many->size_y+100))/100))>>1);
  172.         for(j=0;j<tmp;j++) y_pos+=data->gauge_y_size[j];
  173.  
  174.         data->gdg[i]=(struct Gadget *)NewObject(gclass, NULL,
  175.                         GA_ID,          i,
  176.                         GA_Top,         y_pos,
  177.                         GA_Left,        set->win_border_x+((i)%set->colums)*data->gauge_x_size+((i)%set->colums)*set->win_space_x,
  178.                         GA_Width,       data->gauge_x_size,
  179.                         GA_Height,      (data->Font[i]->tf_YSize*(many->size_y+100))/100,
  180.                         GAU_Type,       many->gauge_type,
  181.                         GAU_Current,    cur,
  182.                         GAU_Max,        max,
  183.                         GAU_Base,       cur,
  184.                         GAU_Label,      many->label,
  185.                         GAU_TextFormat, many->format,
  186.                         GAU_TextFont,   data->Font[i],
  187.                         GAU_LabelPos,   data->labelpos,
  188.                         GAU_FmtIndent,  many->indent,
  189.  
  190.                         GAU_3D,         many->sty_3d,
  191.                         GAU_Border,     many->sty_border,
  192.                         GAU_Background, many->sty_bg,
  193.                         GAU_ShadowLabel,many->sty_shadow,
  194.                         GAU_NoGauge,    many->sty_nogauge,
  195.                         GAU_NoFormat,   many->sty_noformat,
  196.                         GAU_NoBase,     many->sty_nobase,
  197.  
  198.                         GAU_ColLabel,   &many->Colors[col_label],
  199.                         GAU_ColFormat,  &many->Colors[col_format],
  200.                         GAU_ColBase,    &many->Colors[col_base],
  201.                         GAU_ColCurrent, &many->Colors[col_current],
  202.                         GAU_ColNegative,&many->Colors[col_negative],
  203.                         GAU_ColBrightEdg,&many->Colors[col_bright],
  204.                         GAU_ColDarkEdg, &many->Colors[col_dark],
  205.                         GAU_ColBackground,&many->Colors[col_bg],
  206.  
  207.                         TAG_DONE);
  208.         if(!data->gdg[i]) show("Gadget creation failed!");
  209.         else
  210.         {
  211.             SetGadgetAttrs(data->gdg[i],data->win,NULL,TAG_DONE);
  212.             RefreshGList  (data->gdg[i],data->win,NULL,1);
  213.         }
  214.         typ_none_1:
  215.         many=many->next;
  216.     }
  217. }
  218.  
  219. removeGadgets(struct tm_sys_set *set, struct tm_data *data)
  220. {
  221.     int i;
  222.  
  223.     for(i=0;i<data->num_of_gaug;i++)
  224.         if(data->gdg[i])
  225.         {
  226.             DisposeObject(data->gdg[i]);
  227.             data->gdg[i]=0L;
  228.         }
  229. }
  230.